
//
//  SelectContactTableViewHeadView.m
//  OAProject
//
//  Created by yhj on 2017/3/10.
//  Copyright © 2017年 cdnunion. All rights reserved.
//

#import "SelectContactTableViewHeadView.h"

@interface SelectContactTableViewHeadView ()

@property(nonatomic,strong)UIButton *isSelectBtn;

@property(nonatomic,strong)UILabel *nameLabel;

@end

@implementation SelectContactTableViewHeadView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self)
    {
        self.nameLabel.font=Font_Number(14);

        self.isSelectBtn.hidden=NO;

        [self.isSelectBtn setImage:[UIImage imageNamed:@"no_select"] forState:0];
    }
    return self;
}


-(void)setSectionModel:(SelectContactTableViewHeadModel *)sectionModel
{
    _sectionModel=sectionModel;

    self.nameLabel.text=sectionModel.name;

    if (sectionModel.isChoose)
    {
        [self.isSelectBtn setImage:[UIImage imageNamed:@"selected"] forState:0];
    }
    else
    {
        [self.isSelectBtn setImage:[UIImage imageNamed:@"no_select"] forState:0];
    }
}


-(void)isSelectBtnEvent:(UIButton *)sender
{
    if (self.delegate&&[self.delegate respondsToSelector:@selector(isSelectSection:)])
    {
        [self.delegate isSelectSection:self.section];
    }
}


// isSelectBtn
-(UIButton *)isSelectBtn
{
    if (!_isSelectBtn) {
        _isSelectBtn=[UIButton new];
        [self addSubview:_isSelectBtn];
        [_isSelectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(kmargin*3/2,kmargin*3/2));
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(kmargin*4);
        }];
        [_isSelectBtn addTarget:self action:@selector(isSelectBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _isSelectBtn;
}

// nameLabel
- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel=[self getLabelWithText:@"龙江" font:Font_Number(14) textColor:BlackColor textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self addSubview:_nameLabel];
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self.isSelectBtn.mas_right).offset(kmargin);
        }];
    }
    return _nameLabel;
}


@end
